package com.oner365.test.socket.connection;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ShortConnectionClient {
  
  private static final Logger LOGGER = LoggerFactory.getLogger(ShortConnectionClient.class);
  
  public static void main(String[] args) throws IOException {
    Socket socket = new Socket(InetAddress.getLocalHost(), 8883);
    OutputStream outputStream = socket.getOutputStream();
    String data = "传入数据1";
    outputStream.write(data.getBytes());
    InputStream inputStream = socket.getInputStream();
    byte[] buf = new byte[1024];
    int length = inputStream.read(buf);
    LOGGER.info("客户端收到:{}" ,new String(buf, 0, length));
    // 关闭资源
    socket.close();
}

}
